var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/work-flow/index.ts
var work_flow_exports = {};
__export(work_flow_exports, {
  $WorkFlow: () => $WorkFlow,
  WorkFlowPanel: () => import_WorkFlowPanel.default
});
module.exports = __toCommonJS(work_flow_exports);
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_util2 = require("./util");
var import_WorkFlowBatchStartWin = require("./WorkFlowBatchStartWin");
var import_WorkFlowStartWin = require("./WorkFlowStartWin");
var import_WorkFlowPanel = __toESM(require("./WorkFlowPanel"));
async function _startFlowWithPdKey(params) {
  const { appCode, bizCode, dataId, pdkey, cuNo, orgNo, cancelback, processType, formApprovalUserNo } = params;
  if (!appCode || !bizCode) {
    await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.paramError);
    return;
  }
  const data = { appCode, bizCode, dataId, pdkey, cuNo, orgNo };
  if (pdkey) {
    data.pdkey = Array.isArray(pdkey) ? pdkey.join(",") : pdkey;
  }
  if (orgNo) {
    data.orgNo = orgNo;
  }
  const res = await (0, import_functionalComponent.usingProgress)(
    () => import_util.iup.request.body({
      url: "/workflow/processDefinition/getStartProcessExecutionInfo",
      data: { appCode, bizCode, dataId, cuNo, orgNo, processType }
    })
  );
  if (res.code === 0) {
    const processDefinitions = res.data;
    if (processDefinitions.hasRuninfgFlow) {
      await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.bizHasRuningProcInst);
      cancelback == null ? void 0 : cancelback();
      return;
    }
    await (0, import_WorkFlowStartWin.openWorkFlowStartWin)({
      ...params,
      data: processDefinitions,
      autoStart: !!pdkey || processDefinitions.autostart
    });
  } else {
    await (0, import_util2.wfAlert)(import_util2.NGLang.getPdListError, res.errorMsg);
  }
}
async function _startFlowWithNavigation(bizType, bizPhid, busType, callback, cancelback, processType, formApprovalUserNo) {
  const params = import_util.iup.isObject(bizType) ? bizType : { bizType, bizPhid, busType, cancelback, callback, processType, formApprovalUserNo };
  const resp = await import_util.iup.request.get({
    url: "SUP/NavigationCenter/GetProcessBillWorkflow",
    data: {
      billid: params.bizPhid,
      bustype: params.busType
    }
  });
  await _startFlowWithPdKey({
    pdkey: resp.data || null,
    ...params
  });
}
async function _startFlow(appCode, bizCode, dataId, cuNo, orgNo, callback, cancelback, processType, formApprovalUserNo) {
  await _startFlowWithPdKey({
    appCode,
    bizCode,
    dataId,
    cuNo,
    orgNo,
    cancelback,
    callback,
    processType,
    formApprovalUserNo
  });
}
async function _batchStartFlow(bizCode, bacthFlowList, callback, cancelback) {
  const params = import_util.iup.isArray(bacthFlowList) ? bacthFlowList : [];
  if (bacthFlowList.length === 0) {
    await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.paramError);
  } else if (bacthFlowList.length === 1) {
    return $WorkFlow.startFlow({
      bizCode,
      dataId: bacthFlowList[0].dataId,
      cuNo: bacthFlowList[0].cuNo,
      orgNo: bacthFlowList[0].orgNo
    });
  } else if (bacthFlowList.length > 50) {
    await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.batchStartFlowNumberLimit);
  } else {
    const formData = bacthFlowList.map((i) => {
      return {
        ...i,
        bizCode
      };
    });
    const resp = await (0, import_functionalComponent.usingProgress)(
      () => import_util.iup.request.body({
        url: "workflow/processDefinition/getBatchStartProcessExecutionInfo",
        data: {
          formDataIdentityRequests: formData
        }
      })
    );
    if (resp.code === 0) {
      await (0, import_WorkFlowBatchStartWin.openWorkFlowBatchStartWin)({
        callback,
        cancelback,
        formData,
        data: resp.data.processDefinitions
      });
    } else {
      await (0, import_util2.wfAlert)(import_util2.NGLang.getPdListError, resp.errorMsg);
    }
  }
}
async function _startFlowWithPdId(params) {
  const { appCode, bizCode, dataId, pdId, cuNo, orgNo, cancelback } = params;
  if (!appCode || !bizCode) {
    await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.paramError);
    return;
  }
  const data = { appCode, bizCode, dataId, cuNo, orgNo };
  if (orgNo) {
    data.orgNo = orgNo;
  }
  const res = await (0, import_functionalComponent.usingProgress)(
    () => import_util.iup.request.body({
      url: "/workflow/processDefinition/getStartProcessExecutionInfo",
      data: { appCode, bizCode, dataId, cuNo, orgNo }
    })
  );
  if (res.code === 0) {
    const processDefinitions = res.data;
    if (processDefinitions.hasRuninfgFlow) {
      await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.bizHasRuningProcInst);
      cancelback == null ? void 0 : cancelback();
      return;
    }
    processDefinitions.processDefinitions = processDefinitions.processDefinitions.filter((item) => {
      return item["id"] === pdId;
    });
    await (0, import_WorkFlowStartWin.openWorkFlowStartWin)({
      ...params,
      data: processDefinitions,
      autoStart: !!pdId || processDefinitions.autostart
    });
  } else {
    await (0, import_util2.wfAlert)(import_util2.NGLang.getPdListError, res.errorMsg);
  }
}
var $WorkFlow = {
  // 送审
  startFlow(params) {
    return new Promise((resolve, reject) => {
      _startFlow(
        params.appCode || "0100",
        params.bizCode,
        params.dataId,
        params.cuNo,
        params.orgNo,
        (...args) => {
          var _a;
          (_a = params.successCallback) == null ? void 0 : _a.call(params, ...args);
          resolve(args);
        },
        (...args) => {
          var _a;
          (_a = params.cancelCallback) == null ? void 0 : _a.call(params, ...args);
          reject(args);
        },
        params.processType,
        params.formApprovalUserNo
      ).then();
    });
  },
  // 批量送审
  batchStartFlow(params) {
    return new Promise((resolve, reject) => {
      _batchStartFlow(
        params.bizCode,
        params.bacthFlowList,
        (...args) => {
          var _a;
          (_a = params.successCallback) == null ? void 0 : _a.call(params, ...args);
          resolve(args);
        },
        (...args) => {
          var _a;
          (_a = params.cancelCallback) == null ? void 0 : _a.call(params, ...args);
          reject(args);
        }
      ).then();
    });
  },
  startFlowWithNavigation({
    bizType,
    bizPhId,
    busType,
    successCallback,
    cancelCallback,
    processType,
    formApprovalUserNo
  }) {
    return _startFlowWithNavigation(
      bizType,
      bizPhId,
      busType,
      successCallback,
      cancelCallback,
      processType,
      formApprovalUserNo
    ).then();
  },
  // 流程追踪
  showFlowInfo: import_util2.showFlowInfo,
  // 通过piId查看流程信息
  showFlowInfoByPiId: import_util2.showFlowInfoByPiId,
  startFlowWithPdId(params) {
    return new Promise((resolve, reject) => {
      _startFlowWithPdId({
        appCode: params.appCode || "0100",
        bizCode: params.bizCode,
        dataId: params.dataId,
        cuNo: params.cuNo,
        orgNo: params.orgNo,
        pdId: params.pdId,
        callback: (...args) => {
          var _a;
          (_a = params.successCallback) == null ? void 0 : _a.call(params, ...args);
          resolve(args);
        },
        cancelback: (...args) => {
          var _a;
          (_a = params.cancelCallback) == null ? void 0 : _a.call(params, ...args);
          reject(args);
        }
      }).then();
    });
  }
};
import_util.iup.registerExternal({
  getWorkFlowSdk() {
    return $WorkFlow;
  }
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  $WorkFlow,
  WorkFlowPanel
});
